package com.xszx.servlet.user.Cart;

import com.xszx.dao.CartDao;
import com.xszx.dao.impl.CartDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UpdateCartServlet")
public class UpdateCartServlet extends HttpServlet {
    static CartDao cartDao = new CartDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        Integer id = Integer.parseInt(req.getParameter("id"));
        Integer goodsCount = Integer.parseInt(req.getParameter("goodsCount"));
        if (goodsCount > 1) {
            cartDao.updateCartMount(id, goodsCount);
            resp.sendRedirect("GetCartServlet");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
